package com.yesjpt.web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.yesjpt.domain.Notice;
import com.yesjpt.serv.NoticeServ;
import com.yesjpt.util.ContextUtil;
import com.yesjpt.util.L;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "公告")
@RestController
@RequestMapping("/notice")
public class NoticeController {

	@Autowired private NoticeServ serv;
	
	@PostMapping//后面不带任何的URI，post操作由前端指定
	@ApiOperation(value = "保存公告")
	public JSONObject add(@RequestBody Notice notice) {
		L.begin(new Throwable().getStackTrace()[0]);
		return serv.add(notice);
	}

	@GetMapping("/{id}")
	@ApiOperation(value = "根据id获取公告")
	public Notice findById(@PathVariable String id) {
		L.i(new Throwable().getStackTrace()[0]);
		return serv.findById(id);
	}

	@GetMapping("/listByParams")//用得最多，
	@ApiOperation(value = "根据参数查询")
	public List<Notice> listByParams() {
		L.i(new Throwable().getStackTrace()[0] + ", params = " + ContextUtil.getParams());
		return serv.listByParams(ContextUtil.getParams());
	}
	
	@PutMapping//后面不带任何的URI，put操作由前端指定
	@ApiOperation(value = "修改公告")
	public JSONObject update(@RequestBody Notice vo) {
		L.i(new Throwable().getStackTrace()[0]);
		return serv.update(vo);
	}

	@DeleteMapping("/{id}")
	@ApiOperation(value = "删除公告")
	public JSONObject delete(@PathVariable String id) {
		L.i(new Throwable().getStackTrace()[0]);
		return serv.delete(id);
	}

}
